<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        html,
        body,
        #map {
            width: 100%;
            height: 100%;
            padding: 0;
            margin: 0
        }
        /* 隐藏图标 */
        
        .anchorBL,
        .BMap_cpyCtrl {
            display: none;
        }
    </style>
</head>

<body>
    <div id="map"></div>
    <script>
        function init() {
            var map = new BMapGL.Map('map');
            var point = new BMapGL.Point(116.404, 39.915);
            map.centerAndZoom(point, 10);
            map.enableScrollWheelZoom(true); // 滑轮可滚动
            /*
            绘制图标
            Icon(url: String, size: Size , opts: IconOptions )	以给定的图像地址和大小创建图标对象实例 */
            var myIcon = new BMapGL.Icon(
                    'https://s3.bmp.ovh/imgs/2021/09/698b9a134367b9fe.png',
                    new BMapGL.Size(60, 60), {
                        anchor: new BMapGL.Size(0, 0) // 偏移
                    }
                )
                // 奖图放到标注上
            var marker = new BMapGL.Marker(point, {
                icon: myIcon
            })
            map.addOverlay(marker)

            /* 
            绘制线段
            Polyline(points: Array< Point >, opts: PolylineOptions )	创建折线覆盖物对象 */
            var polyline = new BMapGL.Polyline([
                new BMapGL.Point(116.800, 39.800),
                new BMapGL.Point(117.000, 39.820),
                new BMapGL.Point(117.500, 40.820)
            ], {
                strokeColor: 'red', // 线的颜色
                strokeWeight: 10,
                strokeOpacity: 0.5
            });
            map.addOverlay(polyline);

            /* 按照上述方法；利用绘制多边形属性，绘制三角形等图形 */

            /* 
            文本标注
            Label(content: String, opts: LabelOptions )	创建一个文本标注实例。point参数指定了文本标注所在的地理位置
            */
            var label = new BMapGL.Label('哈哈哈哈哈哈哈', {
                position: point, // 定位
                offset: new BMapGL.Size(100, 10), // 偏移
            })
            label.setStyle({
                    width: '100px',
                    height: '20px',
                    padding: '20px',
                    color: '#fff',
                    background: 'red',
                    overflow: 'hidden'
                })
                // 监听点击
            label.addEventListener('click', function(e) {
                alert(e.target.content)
            })
            map.addOverlay(label)

            /* 
            包含信息的窗口
            InfoWindow(content: String | HTMLElement, opts: InfoWindowOptions )	创建一个信息窗实例，其中content支持HTML内容。
            */
            // 或者传入div
            var content = '<div style="color: red;">欢迎学习数据可视化体系课</div>'
            marker.addEventListener('click', function() {
                var InfoWindow = new BMapGL.InfoWindow(
                    '欢迎学习数据可视化体系课', {
                        width: 250,
                        height: 100,
                        title: '说明'
                    }
                );
                map.openInfoWindow(InfoWindow, point);
            })


        }
        window.onload = function() {
            var script = document.createElement('script');
            script.src = 'https://api.map.baidu.com/api?type=webgl&v=1.0&ak=您的密匙&callback=init'
            document.body.appendChild(script)
        }
    </script>
</body>

</html>